package 线程安全;


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket ssk = new ServerSocket(12066);
        Socket socket = ssk.accept();
        InputStream inputStream = socket.getInputStream();

        byte[] bytes = new byte[8];
        int len = 0;
        while (true) {
            OutputStream outputStream = socket.getOutputStream();
            while ((len = inputStream.read(bytes)) != -1) {
                System.out.println(new String(bytes, 0, len));
                //System.out.println("1");
                outputStream.write(bytes, 0, len);
                outputStream.flush();
                //System.out.println("2");
            }
            socket.shutdownOutput();
            System.out.println("finised!");
        }
    }
}
